package com.Nuyoah.demo01.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class MailService {
    @Autowired
    JavaMailSender sender;//直接注入JavaMailSender

    public void sendmail(String from, String to, String cc, String subject, String content) {
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setFrom(from);//发送者
        mail.setTo(to);//收件人
        mail.setCc(cc);//抄送人
        mail.setSubject(subject);//邮件主题
        mail.setText(content);//邮件内容
        sender.send(mail);//发送邮件
    }
    public void sendmail(String from, String to, String subject, String content) {
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setFrom(from);//发送者
        mail.setTo(to);//收件人
        mail.setSubject(subject);//邮件主题
        mail.setText(content);//邮件内容
        sender.send(mail);//发送邮件
    }
}